package com.tequila.core.service.impl;

import com.google.common.collect.Lists;
import com.tequila.core.dao.StoreDao;
import com.tequila.core.service.StoreService;
import com.tequila.domain.dto.StoreDto;
import com.tequila.domain.entity.Store;
import com.tequila.domain.query.StoreQuery;
import fe.core.Assert;
import fe.core.BeanHelper;
import fe.core.Pagination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class StoreServiceImpl implements StoreService {
    public static final Logger logger = LoggerFactory.getLogger(StoreServiceImpl.class);

    @Resource
    private StoreDao storeDao;

    @Override
    public Pagination<StoreDto> queryPageListByParam(StoreQuery query) {
        Assert.assertNotNull(query);
        int total = storeDao.queryPageCountByParam(query);

        List<StoreDto> list = Lists.newArrayList();
        if (total > 0) {
            list = storeDao.queryPageListByParam(query);
        }
        return new Pagination<>(query, list, total);
    }

    @Override
    public StoreDto queryById(Long id) {
        Assert.assertNotNull(id,"id不能为空!");
        Store store = storeDao.queryById(id);
        StoreDto storeDto = new StoreDto();
        BeanHelper.copyProperties(storeDto, store);
        return storeDto;
    }

    @Override
    public List<StoreDto> queryByIdList(List<Long> idList) {
        Assert.assertNotNull(idList,"idList不能为空!");
        return storeDao.queryByIdList(idList);
    }

    @Override
    public List<StoreDto> queryListByParam(StoreQuery query) {
        Assert.assertNotNull(query,"query不能为空!");
        return storeDao.queryListByParam(query);
    }


    @Override
    public Long insert(Store entity) {
        Assert.assertNotNull(entity,"entity不能为空!");
        storeDao.insert(entity);
        return entity.getId();
    }

    @Override
    public Long save(Store entity) {
        Assert.assertNotNull(entity,"entity不能为空!");
        storeDao.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public int updateById(Store param) {
        Assert.assertNotNull(param,"param不能为空!");
        Assert.assertNotNull(param.getId(),"id不能为空!");
        return storeDao.updateById(param);
    }

    @Override
    public int updateSelectiveById(Store param) {
        Assert.assertNotNull(param,"param不能为空!");
        Assert.assertNotNull(param.getId(),"id不能为空!");
        return storeDao.updateSelectiveById(param);
    }

    @Override
    public int deleteById(Long id) {
        Assert.assertNotNull(id,"id不能为空!");
        return storeDao.deleteById(id);
    }

    @Override
    public int deleteByIdList(List<Long> idList) {
        Assert.assertNotNull(idList,"idList不能为空!");
        return storeDao.deleteByIdList(idList);
    }


}
